home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Commun⁄Network / Telnet 2.5.src.ThinkC / source / NCSA Driver / ether.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-27  |  8.7 KB  |  401 lines  |  [TEXT/MPS ]

  1. #ifndef lint
  2. static char *SCCSid = "%W%    (NCSA)    %G%";
  3. #endif
  4. /*
  5. *    ether.c
  6. *     by Gaige B. Paulsen
  7. ****************************************************************************
  8. *                                                                          *
  9. *      Uses    :                                                               *
  10. *      TCP/IP kernel for NCSA Telnet                                       *
  11. *      by Tim Krauskopf                                                    *
  12. *       with Macintosh code by Gaige B. Paulsen                                 *
  13. *                                                                          *
  14. *      National Center for Supercomputing Applications                     *
  15. *      152 Computing Applications Building                                 *
  16. *      605 E. Springfield Ave.                                             *
  17. *      Champaign, IL  61820                                                *
  18. *                                                                          *
  19. *                                                                          *
  20. ****************************************************************************
  21. *
  22. *    EtherNet init and shutdown (and utility) procs.    
  23. *
  24. *    Called by:
  25. *        dlayer.c
  26. *        mactools.c
  27. *        macutil.c
  28. */
  29.  
  30. #include <StdLib.h>
  31. #include <ctype.h>
  32.  
  33. #include <Devices.h>
  34. #include <Dialogs.h>
  35. #include <Files.h>
  36. #include <ROMDefs.h>
  37. #include <Slots.h>
  38. #include <stdio.h>
  39. #include <String.h>
  40. #include <AppleTalk.h>
  41.  
  42. #include "configrec.h"
  43. #include "protocol.h"
  44. #include "data.h"
  45. #include "EtherTalk.h"
  46. #include "hostform.h"
  47. #include "fastnet.h"
  48. #include "maclook.h"
  49. #include "confile.h"
  50. #include "croft.h"
  51.  
  52.  
  53. typedef struct {
  54.     char    node[26];
  55.     char    net[2];
  56. } ABusVarStruct, *ABusVarPtr, **ABusVarHdl;
  57.  
  58. extern int EtherNet;
  59. short ENETdriver;
  60.  
  61. extern ETListen();
  62.  
  63. void ETcall
  64.   (
  65.     EtParam *ep,
  66.     int call
  67.   )
  68. {
  69.     int bkgr=-1;
  70.  
  71.     ep->ioCompletion=0L;
  72.     ep->ioCRefNum = ENETdriver;
  73.     ep->csCode= call;
  74.  
  75.     if (call = EWrite) bkgr=0;
  76.  
  77.     PBControl((ParmBlkPtr) ep, bkgr);
  78. }
  79.  
  80. void getETaddress
  81.   (
  82.     char *store
  83.   )
  84. {
  85.     EtParam EP;
  86.  
  87.     if (EtherNet==-2)
  88.         getFNaddress(store);
  89.     EP.address= store;
  90.     EP.bufsize= 6;
  91.     ETcall(&EP, EGetInfo);
  92. }
  93.  
  94. /*
  95.  * ETfindcard()
  96.  *
  97.  * Finds the EtherNet Card in a Mac II
  98.  *    if *slotp is != 0, then look on that slot for the sResource ID #
  99.  *
  100.  */
  101.  
  102. int ETfindcard
  103.   (
  104.     int *slotp,
  105.     int *spidp
  106.   )
  107. {
  108.     OSErr err;
  109.     SpBlock spb;
  110.  
  111.     spb.spSlot        = *slotp;
  112.     spb.spID        = 0;
  113.     spb.spExtDev    = 0;
  114.     spb.spCategory    = catNetwork;
  115.     spb.spCType     = typeEtherNet;
  116.     spb.spTBMask    = 0x03;
  117.  
  118.     err = SNextTypeSRsrc( &spb);
  119.     *slotp= spb.spSlot;
  120.     *spidp= spb.spID;
  121.  
  122.     if (err)
  123.         return(-1);
  124.     else
  125.         return( 0);
  126. }
  127. #ifdef AZTEC
  128. #asm
  129.     public    _SNextTypeSRsrc
  130. _SNextTypeSRsrc
  131.     move.l    4(sp),a0
  132.     moveq    #$15,D0
  133.     dc.w    $A06E
  134.     rts                
  135.  
  136.     public    _OpenSlot
  137. _OpenSlot
  138.     move.l    4(sp),a0
  139.     move.w    8(sp),d0
  140.     bne.s    os1
  141.     dc.w    $a200
  142.     bra.s    os2
  143. os1:
  144.     dc.w    $a600
  145. os2:
  146.     rts
  147. #endasm
  148. #endif AZTEC
  149.  
  150. int ETclose
  151.   (
  152.     void
  153.   )
  154. {
  155.     /* int err; */
  156.     EtParam EP;
  157.  
  158.     EP.protocol= EARP;
  159.     /* err = */ ETcall(&EP, EDetachPH);
  160.  
  161.     EP.protocol= ERARP;
  162.     /* err = */ ETcall(&EP, EDetachPH);
  163.  
  164.     EP.protocol= EIP;
  165.     /* err = */ ETcall(&EP, EDetachPH);
  166.  
  167.     /*Close( ENETdriver); */
  168.  
  169.     return
  170.         0;
  171. }
  172.  
  173. int ETopen
  174.   (
  175.     void
  176.   )
  177. {
  178.     short err;
  179.     short socket=72, item;
  180.     char buffr[100];
  181.     DialogPtr dtemp;
  182.     EtParam EP;
  183.  
  184.     if (EtherNet<0) {
  185. #ifndef MPW
  186.         err=OpenDriver("\P.ENET0",&ENETdriver );        /* BYU 2.4.8 */
  187. #else 
  188.         err=opendriver(".ENET0",&ENETdriver );
  189. #endif MPW
  190.         ETcall(&EP, 1010);        /* Turn off the Kinetics stuff */
  191.         ETcall(&EP, 1011);
  192.         }
  193.     else {
  194.         SlotDevParam sdpb;
  195.         int slot, spid;
  196.  
  197.         err=-1;                    /* So we can be an error by default */
  198.  
  199.         if (EtherNet <9)        /* No Slot Specified */
  200.             slot=0;
  201.         else
  202.             slot=EtherNet;
  203.  
  204.         if (!ETfindcard( &slot, &spid)) {
  205.             sdpb.ioSlot = slot;
  206.             sdpb.ioID = spid;
  207.             sdpb.ioCompletion = 0L;
  208. #ifndef MPW
  209.             sdpb.ioNamePtr = "\P.ENET";
  210. #else
  211.             sdpb.ioNamePtr = "\p.ENET";
  212. #endif MPW
  213.             sdpb.ioPermssn = fsCurPerm;
  214.             sdpb.ioVRefNum = 0;
  215.             sdpb.ioMix = 0L;
  216.             sdpb.ioFlags = 0;
  217.     
  218.             sprintf(buffr, "Opening the ENET driver for %d(%d)",slot,spid);
  219.             putln(buffr);
  220.  
  221. /* Mac Quadra with Friendly Net Adaptor is             /* BYU 2.4.20 */
  222. /* slot 0, which causes a problem here for             /* BYU 2.4.20 */
  223. /* the NCSA driver because EtherNet = 0              /* BYU 2.4.20 */
  224. /* means AppleTalk.                                    /* BYU 2.4.20 */
  225.             if (!slot)                                /* BYU 2.4.20 */
  226.               EtherNet = 1;                            /* BYU 2.4.20 */
  227.             else                                    /* BYU 2.4.20 */
  228.               EtherNet = slot;                        /* BYU 2.4.20 */
  229.  
  230.             OpenSlot((ParmBlkPtr) &sdpb, FALSE);
  231.             err= sdpb.ioResult;
  232.             ENETdriver = sdpb.ioRefNum;
  233.             }
  234.         }
  235.  
  236.     if (err!=0) { 
  237.             sprintf(buffr,"Failed EtherTalk initialization (%d)\015",err);    /* BYU 2.4.18 - changed \n to \015 */
  238.             putln(buffr);
  239. #ifndef MPW
  240.             ParamText(0L,0L,0L,"\PCouldn't open driver[E]");        /* BYU 2.4.8 */
  241. #else
  242.             paramtext(0L,0L,0L,"Couldn't open driver[E]");
  243. #endif MPW
  244.             dtemp=GetNewDialog(302, (Ptr) 0L, (WindowPtr) -1L);
  245. #if 1                                                            /* BYU 2.4.15 */
  246.             DrawDialog(dtemp);                                    /* BYU 2.4.15 */
  247.             WaitSeconds(5);                                        /* BYU 2.4.15 */
  248.             EtherNet = -100;                                    /* BYU 2.4.15 */
  249. #else                                                            /* BYU 2.4.15 */
  250.             ModalDialog(0L,&item);
  251. #endif                                                            /* BYU 2.4.15 */
  252.             DisposDialog(dtemp);
  253. /*            exit(1);                                            /* BYU 2.4.15 */
  254.             }
  255.  
  256.     EP.address=ETListen;
  257.     EP.protocol= EIP;
  258.     /*err = */ ETcall(&EP, EAttachPH);
  259.     if (/* err != */ 0) { 
  260.             sprintf(buffr,"Failed EtherTalk initialization (%d)\015",err);    /* BYU 2.4.18 - changed \n to \015 */
  261.             putln(buffr);
  262. #ifndef MPW
  263.             ParamText(0L,0L,0L,"\PCouldn't Install IP Handler[E]");        /* BYU 2.4.8 */
  264. #else
  265.             paramtext(0L,0L,0L,"Couldn't Install IP Handler[E]");
  266. #endif MPW
  267.             dtemp=GetNewDialog(302,(Ptr) 0L,(WindowPtr) -1L);
  268. #if 1                                                            /* BYU 2.4.15 */
  269.             DrawDialog(dtemp);                                    /* BYU 2.4.15 */
  270.             WaitSeconds(5);                                        /* BYU 2.4.15 */
  271.             EtherNet = -100;                                    /* BYU 2.4.15 */
  272. #else                                                            /* BYU 2.4.15 */
  273.             ModalDialog(0L,&item);
  274. #endif                                                            /* BYU 2.4.15 */
  275.             DisposDialog(dtemp);
  276.             ETclose();
  277. /*            exit(1);                                            /* BYU 2.4.15 */
  278.             }
  279.  
  280.     EP.address=ETListen;
  281.     EP.protocol= EARP;
  282.     /* err = */ ETcall(&EP, EAttachPH);
  283.     if (/* err != */ 0) { 
  284.             sprintf(buffr,"Failed EtherTalk initialization (%d)\015",err);    /* BYU 2.4.18 - changed \n to \015 */
  285.             putln(buffr);
  286. #ifndef MPW
  287.             ParamText(0L,0L,0L,"\PCouldn't Install ARP Handler[E]");    /* BYU 2.4.8 */
  288. #else
  289.             paramtext(0L,0L,0L,"Couldn't Install ARP Handler[E]");
  290. #endif MPW
  291.             dtemp=GetNewDialog(302,(Ptr) 0L,(WindowPtr) -1L);
  292. #if 1                                                            /* BYU 2.4.15 */
  293.             DrawDialog(dtemp);                                    /* BYU 2.4.15 */
  294.             WaitSeconds(5);                                        /* BYU 2.4.15 */
  295.             EtherNet = -100;                                    /* BYU 2.4.15 */
  296. #else                                                            /* BYU 2.4.15 */
  297.             ModalDialog(0L,&item);
  298. #endif                                                            /* BYU 2.4.15 */
  299.             DisposDialog(dtemp);
  300.             ETclose();
  301. /*            exit(1);                                            /* BYU 2.4.15 */
  302.             }
  303.  
  304.     EP.address=ETListen;
  305.     EP.protocol= ERARP;
  306.     /* err = */ ETcall(&EP, EAttachPH);
  307.     if (/* err != */ 0) { 
  308.             sprintf(buffr,"Failed EtherTalk initialization (%d)\015",err);    /* BYU 2.4.18 - changed \n to \015 */
  309.             putln(buffr);
  310. #ifndef MPW
  311.             ParamText(0L,0L,0L,"\PCouldn't Install RARP Handler[E]");    /* BYU 2.4.8 */
  312. #else
  313.             paramtext(0L,0L,0L,"Couldn't Install RARP Handler[E]");
  314. #endif MPW
  315.             dtemp=GetNewDialog(302,(Ptr) 0L,(WindowPtr) -1L);
  316. #if 1                                                            /* BYU 2.4.15 */
  317.             DrawDialog(dtemp);                                    /* BYU 2.4.15 */
  318.             WaitSeconds(5);                                        /* BYU 2.4.15 */
  319.             EtherNet = -100;                                    /* BYU 2.4.15 */
  320. #else                                                            /* BYU 2.4.15 */
  321.             ModalDialog(0L,&item);
  322. #endif                                                            /* BYU 2.4.15 */
  323.             DisposDialog(dtemp);
  324.             ETclose();
  325. /*            exit(1);                                            /* BYU 2.4.15 */
  326.             }
  327.  
  328.  
  329.     ETcall(&EP, ESetGeneral);
  330.  
  331.     getETaddress( (char *) &nnmyaddr[0]);    /* BYU LSC */
  332.     return(0);
  333. }
  334.  
  335. int netconfig
  336.   (
  337.     char *hardware
  338.   )
  339. {
  340.     extern int nnemac;
  341.     int len;
  342.     char *p, temp[50];
  343.  
  344.     len = strlen(hardware);
  345.  
  346.     p=hardware;
  347.     /*
  348.     if (len <=0)
  349.         return(-1);
  350.     */
  351.  
  352.     while (len--) {
  353.         *p= toupper( *p);
  354.         p++;
  355.         }
  356.  
  357.     if (!strncmp( hardware, "SERIAL", 5))         /* BYU 2.4.15 */
  358.         EtherNet = -100;                        /* BYU 2.4.15 */
  359.  
  360.     if (!strncmp( hardware, "MACTCP", 5))         /* BYU 2.4.16 */
  361.         EtherNet = -99;                            /* BYU 2.4.16 */
  362.  
  363.     if (!strncmp( hardware, "ETHER", 5)) {
  364.         p=hardware+5;
  365.         if (!strncmp( p, "SE",2) || !strncmp(p,"SC",2))
  366.             EtherNet=-1;
  367.         else {
  368.             if (sscanf(p, "%d", &EtherNet)>0) {
  369.                 if (EtherNet>14 || EtherNet<9)
  370.                     EtherNet=1;
  371.                 }
  372.             else
  373.                 EtherNet=1;
  374.             }
  375.         sprintf( temp, "We got ether something (%d)", EtherNet);
  376.         putln(temp);
  377.         }
  378.  
  379.     if (!strncmp( hardware,"FASTNET",7)) {
  380.         extern int SCSI_ID;                        /* The Fastnet Scuzzi ID */
  381.         char temp[100];
  382.  
  383.         EtherNet=-2;
  384.         if (sscanf(hardware+7L,"%d",&len)==1)
  385.             SCSI_ID = len;
  386.         sprintf(temp, "Got one of them FastNet thingies(%d)", SCSI_ID);
  387.         putln(temp);
  388.         }
  389.  
  390.     nnemac = (EtherNet != 0);
  391.     if (!EtherNet) {
  392.         struct config c;
  393.  
  394.         Sgetconfig(&c);
  395.         KIPsetzone((char *) c.zone);        /* BYU LSC */
  396.         }
  397.     initipnum(0);
  398.  
  399.     return(0);
  400. }
  401.